package com.ljj;

import com.ljj.config.AppConfig;
import com.ljj.service.OrderService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class App 
{
    public static void main(String[] args) {
        // 启动Spring容器
        AnnotationConfigApplicationContext context =
                new AnnotationConfigApplicationContext(AppConfig.class);

        // 获取代理对象
        OrderService orderService = context.getBean(OrderService.class);

        System.out.println("\n--- 测试 add ---");
        try {
            orderService.add("iPhone", 2);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        System.out.println("\n--- 测试 delete ---");
        try {
            orderService.delete("iPad");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        System.out.println("\n--- 测试 find ---");
        try {
            orderService.find("MacBook");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        // 关闭容器
        context.close();
    }
}